package com.fitz.example.filter;

import com.fitz.core.context.FilterConstants;
import com.fitz.core.context.RequestContext;
import com.fitz.core.filter.AbstractFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
public class AuthFilter extends AbstractFilter {

    @Override
    public String routeType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int order() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext rtx = RequestContext.getCurrentContext();
        HttpServletRequest request = rtx.getRequest();
        log.info("请求方法:{},url:{}",request.getMethod(),request.getRequestURI());
        rtx.setUrl("127.0.0.1:8081/forward/test");
        return null;
    }
}
